import type { PiniaPluginContext } from "pinia";

// 日志插件
export const createPiniaLogger = (params: { user: string }) => {
  return (context: PiniaPluginContext) => {
    const { store } = context;

    store.$onAction(({ name, args, after, onError }) => {
      console.group(`用户${params.user}在${name}操作`);
      console.log("args", args);
      after(() => {
        console.log(`用户${params.user}在${name}操作后`, store.$state);
      });
      onError((error) => {
        console.log(`用户${params.user}在${name}操作出错`, error);
      });
      console.groupEnd();
    });
  };
};
